﻿/******************************************************   
创建者: 梁家健
创建时间: 2017-04-24
修改:
修改时间: 
功能: 企划结果汇总
 ******************************************************/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI;
using com.nm.ApiServer;
using NHibernateVertica;
using george.Data;
using com.nm.library.Helper;
using PlanAPI.model;
using com.nm.ApiServer.Attributes;
using com.nm.Attributes;
using com.nm.library;

namespace PlanAPI
{
    [Description("企划结果汇总")]
    public class PLItemSkcForPCHandler : BaseHandler
    {
        public VerticaDataHelper Helper { get; set; } = new VerticaDataHelper();

        public enum PriceOrColor
        {
            Price = 0,
            Color = 1
        }

        /// Writer：梁家健
        /// Create Date：2017-04-24
        [MustLogin]
        [Description("企划结果店铺汇总列表")]
        [ReturnType(typeof(IList<PLItemSkcForPCModel.ShopListModel>))]
        public ApiResult GetPLItemSkcForPCShopList([ParamDescription("年-月")] DateTime? YearMonth,
            [ParamDescription("是否选中周")] int CountryAreaCity = 1,
            [ParamDescription("商品区域")] string ParentAreaID = "", [ParamDescription("店铺")] string Keys = "")
        {
            try
            {
                if (string.IsNullOrEmpty(UserInfo.UserCompanyId))
                {
                    return Error("该用户不属于任何公司!");
                }
                if (string.IsNullOrEmpty(UserInfo.UserExtrSource))
                {
                    return Error("该用户所在公司没有任何数据源!");
                }
                if (!YearMonth.HasValue) return Error("请选择日期");
                var dt = ReturnPLItemSkcForPCShopList(YearMonth.Value.Year, YearMonth.Value.Month, ParentAreaID, CountryAreaCity, Keys);
                var list = ModelConvertHelper<PLItemSkcForPCModel.ShopListModel>.ConvertToModel(dt).ToList();
                return Success(list);
            }
            catch (Exception ex)
            {
                return Error(ex.Message);
            }
        }

        /// <summary>
        /// 返回企划结果店铺汇总列表
        /// </summary>
        /// <param name="YearMonth"></param>
        /// <param name="ParentAreaID"></param>
        /// <param name="Keys"></param>
        /// <returns></returns>
        /// Writer：梁家健
        /// Create Date：2017-04-24
        public DataTable ReturnPLItemSkcForPCShopList(long Yearv, long Monthv, string ParentAreaID, int CountryAreaCity, string Keys)
        {
            try
            {
                var con0 = @"";
                var con1 = @"";
                var con2 = @"";
                var con3 = @"";
                var con4 = @"";
                if (CountryAreaCity == 2)
                {
                    con0 = @",pc.ShopID ";
                    con1 = @" INNER JOIN ( SELECT *
                                 FROM   ndw.ndw_Shop
                                 WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                                        AND CompanyID = '{UserInfo.UserCompanyId}'
                               ) shop ON table1.ShopID = shop.ShopID
                                         AND dict.ExtrSource = shop.ExtrSource
                                         AND dict.CompanyID = shop.CompanyID ";
                    con2 = @",table1.ShopID";
                    con3 = string.IsNullOrEmpty(Keys)
                        ? ""
                        : $@" and (shop.ShopName like '%{Keys}%' or shop.ShopCode like '%{Keys}%') ";
                    con4 = @",table1.ShopID ,
                        shop.ShopName ";
                }
                var sql = $@"SELECT  table1.Yearv ,
        table1.Monthv ,
        table1.SumPrice ,
        table1.SumSKC ,
        dictValue AS ParentAreaID ,
        dictName AS ParentAreaName
        {con4}
FROM    ndw.ndw_global_dictionary dict
        LEFT JOIN ( SELECT  pc.ExtrSource ,
                            pc.CompanyID ,
                            pc.Yearv ,
                            pc.Monthv ,
                            pc.ParentAreaID ,
                            SUM(pc.DeepQty * pc.PriceColorSKCQty
                                * per.PriceValue) AS SumPrice ,
                            SUM(pc.PriceColorSKCQty) AS SumSKC
                            {con0}
                    FROM    ngoods.ngoods_PL_Item_SkcForPCDetail pc
                            LEFT JOIN ( SELECT  *
                                        FROM    ngoods.ngoods_PL_Bas_PricePeriod
                                        WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                                                AND CompanyID = '{UserInfo.UserCompanyId}'
                                      ) per ON per.PriceName = pc.PriceColorName
                                               AND per.ExtrSource = pc.ExtrSource
                                               AND per.CompanyID = pc.CompanyID
                    WHERE   pc.ExtrSource = '{UserInfo.UserExtrSource}'
                            AND pc.CompanyID = '{UserInfo.UserCompanyId}'
                            AND pc.Yearv = {Yearv}
                            AND pc.Monthv = {Monthv}
                            AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                    GROUP BY pc.Yearv ,
                            pc.Monthv ,
                            pc.ParentAreaID
                            {con0}
                    
                  ) table1 ON table1.ParentAreaID = dict.dictValue
                              AND table1.ExtrSource = dict.ExtrSource
                              AND table1.CompanyID = dict.CompanyID
        {con1}
WHERE   dict.parentDictValue = '商品区域'
        AND dict.ExtrSource = '{UserInfo.UserExtrSource}'
        AND dict.CompanyID = '{UserInfo.UserCompanyId}'
        {(string.IsNullOrEmpty(ParentAreaID) ? "" : $@" and dict.dictValue='{ParentAreaID}' ")}
        {con3}
ORDER BY dictValue
        {con2}";
                var cmd = Helper.GetSqlStringCommand(sql);
                return Helper.ExecuteDataTable(cmd);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// Writer：梁家健
        /// Create Date：2017-04-24
        [MustLogin]
        [Description("企划结果汇总列表")]
        [ReturnType(typeof(PaperData<IGrouping<string, PLItemSkcForPCModel.ListModel>>))]
        public ApiResult GetPLItemSkcForPCList([ParamDescription("年-月")] DateTime? YearMonth,
            [ParamDescription("商品区域")] string ParentAreaID = "", [ParamDescription("店铺")] string ShopID = "",
            [ParamDescription("是否选中周")] int CountryAreaCity = 0,
            [ParamDescription("是否选中周")] bool isWeek = false, [ParamDescription("是否选中系列")] bool isSeries = false,
            [ParamDescription("是否选中商品层")] bool isMaterialProperty = false, [ParamDescription("是否选中品类")] bool isModel = false,
            [ParamDescription("是否选中小品类")] bool isItem = false, [ParamDescription("是否选中深度")] bool isDeep = false,
            [ParamDescription("是否选中价格带")] bool isPrice = false,
            [ParamDescription("页码")] int Page = 1, [ParamDescription("页数")] int Size = 10)
        {
            try
            {
                if (string.IsNullOrEmpty(UserInfo.UserCompanyId))
                {
                    return Error("该用户不属于任何公司!");
                }
                if (string.IsNullOrEmpty(UserInfo.UserExtrSource))
                {
                    return Error("该用户所在公司没有任何数据源!");
                }
                if (!YearMonth.HasValue) return Error("请选择日期");
                if (CountryAreaCity != 0 && string.IsNullOrEmpty(ParentAreaID) && string.IsNullOrEmpty(ShopID)) return Error("商品区域或店铺未选！");
                var count = ReturnPLItemSkcForPCCount(YearMonth.Value.Year, YearMonth.Value.Month, CountryAreaCity,
                    ParentAreaID, ShopID, isWeek,
                    isSeries, isMaterialProperty, isModel, isItem, isDeep, isPrice);
                var result = PaperData<IGrouping<string, PLItemSkcForPCModel.ListModel>>.Create(count, Size, Page);
                var dt = ReturnPLItemSkcForPCList(YearMonth.Value.Year, YearMonth.Value.Month, CountryAreaCity,
                    ParentAreaID, ShopID, isWeek, isSeries,
                    isMaterialProperty, isModel, isItem, isDeep, isPrice, Page, Size);
                var list = ModelConvertHelper<PLItemSkcForPCModel.ListModel>.ConvertToModel(dt).ToList();
                IList<IGrouping<string, PLItemSkcForPCModel.ListModel>> group;
                ReturnGroupByCountry(list, CountryAreaCity, isWeek, isSeries, isMaterialProperty, isModel, isItem, isDeep,
                    isPrice, out group);
                result.Items = group;
                return Success(result);
            }
            catch (Exception ex)
            {
                return Error(ex.Message);
            }
        }

        /// <summary>
        /// 返回分组
        /// </summary>
        /// <param name="list"></param>
        /// <param name="CountryAreaCity"></param>
        /// <param name="isWeek"></param>
        /// <param name="isSeries"></param>
        /// <param name="isMaterialProperty"></param>
        /// <param name="isItem"></param>
        /// <param name="isDeep"></param>
        /// <param name="isPrice"></param>
        /// <param name="group"></param>
        public void ReturnGroupByCountry(
            IList<PLItemSkcForPCModel.ListModel> list, int CountryAreaCity, bool isWeek, bool isSeries,
            bool isMaterialProperty, bool isModel, bool isItem, bool isDeep, bool isPrice, out IList<IGrouping<string, PLItemSkcForPCModel.ListModel>> group)
        {
            group = list.GroupBy(d => d.Yearv + "_" + d.Monthv).ToList();
            switch (CountryAreaCity)
            {
                case 0:
                    {
                        #region isWeek--True
                        if (isWeek)
                        {
                            if (isSeries)
                            {
                                if (isMaterialProperty)
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv +
                                                                "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                                "_" + d.ModelID + "_" +
                                                                d.ItemID)
                                                        .ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                            "_" + d.ModelID + "_" +
                                                            d.ItemID).ToList()
                                                    : list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv +
                                                                "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                                "_" + d.ModelID)
                                                        .ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                        "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv +
                                                                "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                                "_" +
                                                                d.ItemID)
                                                        .ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                            "_" +
                                                            d.ItemID).ToList()
                                                    : list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv +
                                                                "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty)
                                                        .ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.Weekv + "_" + d.SeriesID).ToList();
                                        }
                                    }
                                }
                                else
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.ModelID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.Weekv + "_" + d.SeriesID + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.Weekv + "_" + d.SeriesID).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.SeriesID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.SeriesID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.Weekv + "_" + d.SeriesID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.Weekv).ToList();
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (isMaterialProperty)
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty + "_" + d.ModelID + "_" +
                                                            d.ItemID).ToList()
                                                    : list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv +
                                                                "_" + d.Weekv + "_" + d.MaterialProperty + "_" + d.ModelID)
                                                        .ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv +
                                                        "_" + d.Weekv + "_" + d.MaterialProperty + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.Weekv + "_" + d.MaterialProperty).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty + "_" +
                                                            d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv +
                                                        "_" + d.Weekv + "_" + d.MaterialProperty).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.Weekv).ToList();
                                        }
                                    }
                                }
                                else
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.ModelID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv +
                                                        "_" + d.Weekv + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv +
                                                        "_" + d.Weekv).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv).ToList();
                                            }
                                        }
                                        else
                                        {
                                            if (isPrice)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.Weekv).ToList();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                        #region isWeek--false

                        else
                        {
                            if (isSeries)
                            {
                                if (isMaterialProperty)
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.SeriesID + "_" + d.MaterialProperty + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv +
                                                                "_" + d.SeriesID + "_" + d.MaterialProperty + "_" +
                                                                d.ModelID + "_" + d.ItemID)
                                                        .ToList()
                                                    : list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv +
                                                                "_" + d.SeriesID + "_" + d.MaterialProperty + "_" + d.ModelID)
                                                        .ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.SeriesID + "_" + d.MaterialProperty + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.SeriesID + "_" + d.MaterialProperty).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv +
                                                                "_" + d.SeriesID + "_" + d.MaterialProperty + "_" + d.ItemID)
                                                        .ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.SeriesID + "_" + d.MaterialProperty).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.SeriesID + "_" + d.MaterialProperty).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" +
                                                        d.SeriesID).ToList();
                                        }
                                    }
                                }
                                else
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.SeriesID + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.SeriesID + "_" + d.ModelID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.SeriesID + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv +
                                                        "_" + d.SeriesID + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv +
                                                        "_" + d.SeriesID).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.SeriesID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.SeriesID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.SeriesID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            if (isPrice)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.SeriesID).ToList();
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (isMaterialProperty)
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.MaterialProperty + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv +
                                                                "_" + d.MaterialProperty + "_" + d.ModelID + "_" + d.ItemID)
                                                        .ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.MaterialProperty + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv +
                                                        "_" + d.MaterialProperty + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv +
                                                        "_" + d.MaterialProperty).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.MaterialProperty +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.MaterialProperty + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.MaterialProperty).ToList();
                                            }
                                        }
                                        else
                                        {
                                            if (isPrice)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv +
                                                            "_" + d.MaterialProperty).ToList();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ModelID +
                                                                "_" +
                                                                d.ItemID)
                                                        .ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ModelID +
                                                            "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            if (isPrice)
                                            {
                                                group = list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ModelID).ToList();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv +
                                                                "_" +
                                                                d.ItemID)
                                                        .ToList();
                                            }
                                            else
                                            {
                                                if (isPrice)
                                                {
                                                    group =
                                                        list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv +
                                                                "_" + d.ItemID).ToList();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        #endregion
                    }
                    break;
                case 1:
                    {
                        group =
                            list.GroupBy(d => d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID).ToList();

                        #region isWeek--True

                        if (isWeek)
                        {
                            if (isSeries)
                            {
                                if (isMaterialProperty)
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                                "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                                "_" + d.ModelID +
                                                                "_" +
                                                                d.ItemID)
                                                        .ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                            "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList()
                                                    : list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                                "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                                "_" + d.ModelID)
                                                        .ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty + "_" +
                                                        d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                                "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                                "_" +
                                                                d.ItemID)
                                                        .ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                            "_" +
                                                            d.ItemID).ToList()
                                                    : list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                                "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty)
                                                        .ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.Weekv + "_" + d.SeriesID).ToList();
                                        }
                                    }
                                }
                                else
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.ModelID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.Weekv + "_" + d.SeriesID + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.Weekv + "_" + d.SeriesID).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.SeriesID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.SeriesID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.Weekv + "_" + d.SeriesID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.Weekv).ToList();
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (isMaterialProperty)
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty + "_" + d.ModelID + "_" +
                                                            d.ItemID).ToList()
                                                    : list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                                "_" + d.Weekv + "_" + d.MaterialProperty + "_" + d.ModelID)
                                                        .ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                        "_" + d.Weekv + "_" + d.MaterialProperty + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.Weekv + "_" + d.MaterialProperty).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty + "_" +
                                                            d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                        "_" + d.Weekv + "_" + d.MaterialProperty).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.Weekv).ToList();
                                        }
                                    }
                                }
                                else
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.ModelID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                        "_" + d.Weekv + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                        "_" + d.Weekv).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv).ToList();
                                            }
                                        }
                                        else
                                        {
                                            if (isPrice)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.Weekv).ToList();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                        #region isWeek--false

                        else
                        {
                            if (isSeries)
                            {
                                if (isMaterialProperty)
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.SeriesID + "_" + d.MaterialProperty + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                                "_" + d.SeriesID + "_" + d.MaterialProperty + "_" +
                                                                d.ModelID + "_" + d.ItemID)
                                                        .ToList()
                                                    : list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                                "_" + d.SeriesID + "_" + d.MaterialProperty + "_" + d.ModelID)
                                                        .ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.SeriesID + "_" + d.MaterialProperty + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.SeriesID + "_" + d.MaterialProperty).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                                "_" + d.SeriesID + "_" + d.MaterialProperty + "_" + d.ItemID)
                                                        .ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.SeriesID + "_" + d.MaterialProperty).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.SeriesID + "_" + d.MaterialProperty).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.SeriesID).ToList();
                                        }
                                    }
                                }
                                else
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.SeriesID + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.SeriesID + "_" + d.ModelID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.SeriesID + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                        "_" + d.SeriesID + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                        "_" + d.SeriesID).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.SeriesID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.SeriesID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.SeriesID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            if (isPrice)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.SeriesID).ToList();
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (isMaterialProperty)
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.MaterialProperty + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                                "_" + d.MaterialProperty + "_" + d.ModelID + "_" + d.ItemID)
                                                        .ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.MaterialProperty + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                        "_" + d.MaterialProperty + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                        "_" + d.MaterialProperty).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.MaterialProperty +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.MaterialProperty + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.MaterialProperty).ToList();
                                            }
                                        }
                                        else
                                        {
                                            if (isPrice)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                            "_" + d.MaterialProperty).ToList();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                                d.ModelID +
                                                                "_" +
                                                                d.ItemID)
                                                        .ToList();
                                            }
                                            else
                                            {
                                                if (isPrice)
                                                {
                                                    group =
                                                        list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                                d.ModelID +
                                                                "_" + d.ItemID).ToList();
                                                }
                                                else
                                                {
                                                    group =
                                                        list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                                d.ModelID).ToList();
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (isPrice)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                            d.ModelID).ToList();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                                "_" +
                                                                d.ItemID)
                                                        .ToList();
                                            }
                                            else
                                            {
                                                if (isPrice)
                                                {
                                                    group =
                                                        list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID +
                                                                "_" + d.ItemID).ToList();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        #endregion
                    }
                    break;
                case 2:
                    {
                        group =
                            list.GroupBy(d => d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID).ToList();

                        #region isWeek--True

                        if (isWeek)
                        {
                            if (isSeries)
                            {
                                if (isMaterialProperty)
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                                d.ShopID +
                                                                "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                                "_" + d.ModelID +
                                                                "_" +
                                                                d.ItemID)
                                                        .ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                            "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList()
                                                    : list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                                d.ShopID +
                                                                "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                                "_" + d.ModelID)
                                                        .ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty + "_" +
                                                        d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                                d.ShopID +
                                                                "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                                "_" +
                                                                d.ItemID)
                                                        .ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                            "_" +
                                                            d.ItemID).ToList()
                                                    : list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                                d.ShopID +
                                                                "_" + d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty)
                                                        .ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.Weekv + "_" + d.SeriesID + "_" + d.MaterialProperty).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.Weekv + "_" + d.SeriesID).ToList();
                                        }
                                    }
                                }
                                else
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.ModelID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.Weekv + "_" + d.SeriesID + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.Weekv + "_" + d.SeriesID).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.SeriesID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.SeriesID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.SeriesID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.Weekv + "_" + d.SeriesID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.Weekv).ToList();
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (isMaterialProperty)
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty + "_" + d.ModelID + "_" +
                                                            d.ItemID).ToList()
                                                    : list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                                "_" + d.Weekv + "_" + d.MaterialProperty + "_" + d.ModelID)
                                                        .ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" + d.Weekv + "_" + d.MaterialProperty + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" + d.MaterialProperty + "_" +
                                                        d.Weekv).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty + "_" +
                                                            d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.MaterialProperty).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" + d.Weekv + "_" + d.MaterialProperty).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.Weekv).ToList();
                                        }
                                    }
                                }
                                else
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.ModelID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.ShopID +
                                                        "_" + d.Weekv + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.ShopID +
                                                        "_" + d.Weekv).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv).ToList();
                                            }
                                        }
                                        else
                                        {
                                            if (isPrice)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.Weekv).ToList();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                        #region isWeek--false

                        else
                        {
                            if (isSeries)
                            {
                                if (isMaterialProperty)
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.SeriesID + "_" + d.MaterialProperty + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                                d.ShopID +
                                                                "_" + d.SeriesID + "_" + d.MaterialProperty + "_" +
                                                                d.ModelID + "_" + d.ItemID)
                                                        .ToList()
                                                    : list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                                "_" + d.SeriesID + "_" + d.MaterialProperty + "_" + d.ModelID)
                                                        .ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.SeriesID + "_" + d.MaterialProperty + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.SeriesID + "_" + d.MaterialProperty).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.SeriesID + "_" + d.MaterialProperty +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                                d.ShopID +
                                                                "_" + d.SeriesID + "_" + d.MaterialProperty + "_" + d.ItemID)
                                                        .ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.SeriesID + "_" + d.MaterialProperty).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.SeriesID + "_" + d.MaterialProperty).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                        "_" +
                                                        d.SeriesID).ToList();
                                        }
                                    }
                                }
                                else
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.SeriesID + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.SeriesID + "_" + d.ModelID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.SeriesID + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.ShopID +
                                                        "_" + d.SeriesID + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.ShopID +
                                                        "_" + d.SeriesID).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.SeriesID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.SeriesID + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.SeriesID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            if (isPrice)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.SeriesID).ToList();
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (isMaterialProperty)
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.MaterialProperty + "_" + d.ModelID +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                                "_" + d.MaterialProperty + "_" + d.ModelID + "_" + d.ItemID)
                                                        .ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.MaterialProperty + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            group = isPrice
                                                ? list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.ShopID +
                                                        "_" + d.MaterialProperty + "_" + d.ModelID).ToList()
                                                : list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.ShopID +
                                                        "_" + d.MaterialProperty).ToList();
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.MaterialProperty +
                                                            "_" +
                                                            d.ItemID).ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.MaterialProperty + "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.MaterialProperty).ToList();
                                            }
                                        }
                                        else
                                        {
                                            if (isPrice)
                                            {
                                                group =
                                                    list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" + d.ShopID +
                                                            "_" + d.MaterialProperty).ToList();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (isModel)
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                                d.ShopID + "_" + d.ModelID +
                                                                "_" +
                                                                d.ItemID)
                                                        .ToList();
                                            }
                                            else
                                            {
                                                group = isPrice
                                                    ? list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                            d.ShopID + "_" + d.ModelID +
                                                            "_" + d.ItemID).ToList()
                                                    : list.GroupBy(
                                                        d =>
                                                            d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                            d.ShopID + "_" + d.ModelID).ToList();
                                            }
                                        }
                                        else
                                        {
                                            if (isPrice)
                                            {
                                                group = list.GroupBy(
                                                    d =>
                                                        d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                        d.ShopID + "_" + d.ModelID).ToList();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (isItem)
                                        {
                                            if (isDeep)
                                            {
                                                group =
                                                    list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                                d.ShopID +
                                                                "_" +
                                                                d.ItemID)
                                                        .ToList();
                                            }
                                            else
                                            {
                                                if (isPrice)
                                                {
                                                    group =
                                                        list.GroupBy(
                                                            d =>
                                                                d.Yearv + "_" + d.Monthv + "_" + d.ParentAreaID + "_" +
                                                                d.ShopID +
                                                                "_" + d.ItemID).ToList();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        #endregion
                    }
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 返回企划结果汇总列表
        /// </summary>
        /// <param name="Yearv"></param>
        /// <param name="Monthv"></param>
        /// <param name="ShopID"></param>
        /// <param name="isWeek"></param>
        /// <param name="isSeries"></param>
        /// <param name="isMaterialProperty"></param>
        /// <param name="isItem"></param>
        /// <param name="isDeep"></param>
        /// <param name="isPrice"></param>
        /// <param name="Page"></param>
        /// <param name="Size"></param>
        /// <returns></returns>
        /// Writer：梁家健
        /// Create Date：2017-04-24
        public DataTable ReturnPLItemSkcForPCList(int Yearv, int Monthv, int CountryAreaCity, string ParentAreaID, string ShopID, bool isWeek, bool isSeries,
            bool isMaterialProperty, bool isModel, bool isItem, bool isDeep, bool isPrice, int Page, int Size)
        {
            try
            {
                var con0 = " ";
                var con1 = " ";
                var con2 = " ";
                var con3 = " ";
                var con4 = " ";
                var con5 = " ";
                var con6 = " ";
                var con7 = " ";
                var con8 = " ";
                var con9 = " ";
                var con10 = " ";
                var con11 = " ";
                var con12 = " ";
                var con13 = " ";
                var con14 = " ";
                var con15 = " ";
                switch (CountryAreaCity)
                {
                    case 0:
                        break;
                    case 1:
                        con12 = @" ,
                                pc.ParentAreaID ,
                                dictName as ParentAreaName ";
                        con13 = @" INNER JOIN ( SELECT *
                                         FROM   ndw.ndw_global_dictionary
                                         WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                                                AND CompanyID = '{UserInfo.UserCompanyId}'
                                       ) dict ON pc.ParentAreaID = dict.dictValue
                                                 AND pc.ExtrSource = dict.ExtrSource
                                                 AND pc.CompanyID = dict.CompanyID ";
                        con14 = @" AND table2.ParentAreaID = pc.ParentAreaID ";
                        con9 = @" ,table2.ParentAreaID,
                                table2.ParentAreaName ";
                        con10 = $@" and pc.ParentAreaID='{ParentAreaID}' ";
                        con11 = @" ,
                                pc.ParentAreaID ,
                                dictName ";
                        con15 = @" ,
                                table3.ParentAreaID ,
                                table3.ParentAreaName ";
                        break;
                    case 2:
                        con12 = @" ,
                                pc.ParentAreaID ,
                                pc.ShopID ,
                                shop.ShopName ";
                        con13 = @" INNER JOIN ( SELECT *
                                         FROM   ndw.ndw_global_dictionary
                                         WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                                                AND CompanyID = '{UserInfo.UserCompanyId}'
                                       ) dict ON pc.ParentAreaID = dict.dictValue
                                                 AND pc.ExtrSource = dict.ExtrSource
                                                 AND pc.CompanyID = dict.CompanyID ";
                        con14 = @" AND table2.ParentAreaID = pc.ParentAreaID
                                AND table2.ShopID = pc.ShopID ";
                        con9 = @" ,table2.ParentAreaID ,
                                table2.ShopID ,
                                table2.ShopName ";
                        con10 = $@" and pc.ShopID='{ShopID}' ";
                        con11 = @" ,
                                pc.ParentAreaID ,
                                pc.ShopID ,
                                shop.ShopName ";
                        con15 = @" ,
                                table3.ParentAreaID ,
                                table3.ShopID ,
                                table3.ShopName ";
                        break;
                    default:
                        break;
                }
                GetConditionsForPLItemSkcForPCList(isWeek, isSeries, isMaterialProperty, isModel, isItem, isDeep, isPrice, con15,
                    out con0, out con1, out con2, out con3,
                    out con4, out con5, out con6, out con7, out con8);
                var sql = $@"{con7}
SELECT  table2.* {con2}
FROM    ( SELECT    *
          FROM      ( SELECT    pc.ExtrSource ,
                                pc.CompanyID ,
                                pc.Yearv ,
                                pc.Monthv
                                {con12}
                                {con0},
                                ROW_NUMBER() OVER ( ORDER BY pc.Yearv , pc.Monthv {con11} {con0} ) AS Row
                      FROM      ngoods.ngoods_PL_Item_SkcForPCDetail pc
                                {con13}
                                {con3}
                      WHERE   pc.ExtrSource = '{UserInfo.UserExtrSource}'
                                AND pc.CompanyID = '{UserInfo.UserCompanyId}'
                                AND pc.Yearv = {Yearv}
                                AND pc.Monthv = {Monthv}
                                and pc.PriceOrColor={(int)PriceOrColor.Price}
                                {con10}
                      GROUP BY  pc.ExtrSource ,
                                pc.CompanyID ,
                                pc.Yearv ,
                                pc.Monthv 
                                {con11}
                                {con0}
                    ) table1
          WHERE     Row BETWEEN ( {Page} - 1 ) * {Size} + 1 AND {Page}
                    * {Size}
        ) table2
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table2.ExtrSource = pc.ExtrSource
                           AND table2.CompanyID = pc.CompanyID
                           AND table2.Yearv = pc.Yearv
                           AND table2.Monthv = pc.Monthv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                                                      {con14}
                                                      {con5}
        {con4}
GROUP BY table2.ExtrSource ,
        table2.CompanyID ,
        table2.Yearv ,
        table2.Monthv ,
        table2.Row
        {con9}
        {con1} 
        {con6}
ORDER BY table2.Row
        {con6}
{con8}";
                var cmd = Helper.GetSqlStringCommand(sql);
                return Helper.ExecuteDataTable(cmd);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// 获取条件
        /// </summary>
        /// <param name="isWeek"></param>
        /// <param name="isSeries"></param>
        /// <param name="isMaterialProperty"></param>
        /// <param name="isItem"></param>
        /// <param name="isDeep"></param>
        /// <param name="isPrice"></param>
        /// <param name="con0"></param>
        /// <param name="con1"></param>
        /// <param name="con2"></param>
        /// <param name="con3"></param>
        /// <param name="con4"></param>
        /// <param name="con5"></param>
        /// <param name="con6"></param>
        public void GetConditionsForPLItemSkcForPCList(bool isWeek, bool isSeries,
            bool isMaterialProperty, bool isModel, bool isItem, bool isDeep, bool isPrice, string con, out string con0,
            out string con1, out string con2, out string con3, out string con4, out string con5, out string con6,
            out string con7, out string con8)
        {
            con0 = " ";
            con1 = " ";
            con2 = " ";
            con3 = " ";
            con4 = " ";
            con5 = " ";
            con6 = " ";
            con7 = " ";
            con8 = " ";

            #region isWeek--True

            if (isWeek)
            {
                if (isSeries)
                {
                    if (isMaterialProperty)
                    {
                        if (isModel)
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isWeek,isSeries,isMaterialProperty,isModel,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.MaterialProperty,table2.ModelID,table2.ModelName,table2.ItemID,table2.SeriesName,table2.ItemName ";

                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND table3.Weekv = pc.Weekv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.SeriesID = pc.SeriesID
                           AND table3.MaterialProperty = pc.MaterialProperty
                           AND table3.ModelID = pc.ModelID
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.ExtrSource ,
        table3.CompanyID ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Weekv ,
        table3.Row ,
        table3.SeriesID ,
        table3.MaterialProperty ,
        table3.ModelID ,
        table3.ModelName ,
        table3.ItemID ,
        table3.SeriesName ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.MaterialProperty,table2.ModelID,table2.ModelName,table2.ItemID,table2.SeriesName,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isWeek,isSeries,isMaterialProperty,isModel,isItem

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.MaterialProperty,table2.ModelID,table2.ModelName,table2.ItemID,table2.SeriesName,table2.ItemName ";

                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,series.SeriesName,pc.ModelID,model.ModelName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.ModelID,table2.ModelName,table2.MaterialProperty,table2.SeriesName,item.ItemName ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isWeek,isSeries,isMaterialProperty,isModel,isDeep

                                if (isPrice)
                                {
                                    con0 =
                                        @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,series.SeriesName,pc.ModelID,model.ModelName ";
                                    con1 =
                                        @" ,table2.Weekv,table2.SeriesID,table2.MaterialProperty,table2.SeriesName,table2.ModelID,table2.ModelName ";

                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName,pc.MaterialProperty ";
                                    con1 = @" ,table2.Weekv,table2.SeriesID,table2.SeriesName,table2.MaterialProperty ";
                                    con2 = @" ,pc.ModelID ,
        model.ModelName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON table2.ModelID = model.ModelID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.Weekv = pc.Weekv
                                        AND table2.SeriesID = pc.SeriesID
                                        AND table2.MaterialProperty = pc.MaterialProperty ";
                                    con6 = @" ,pc.ModelID,model.ModelName ";
                                }

                                #endregion
                            }
                        }
                        else
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isWeek,isSeries,isMaterialProperty,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.MaterialProperty,table2.ItemID,table2.SeriesName,table2.ItemName ";

                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource 
                                LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ItemID = pc.ItemID ";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND table3.Weekv = pc.Weekv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.SeriesID = pc.SeriesID
                           AND table3.MaterialProperty = pc.MaterialProperty
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
GROUP BY table3.CompanyID ,
        table3.ExtrSource ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Weekv ,
        table3.Row ,
        table3.SeriesID ,
        table3.MaterialProperty ,
        table3.ItemID ,
        table3.SeriesName ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.MaterialProperty,table2.ItemID,table2.SeriesName,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource 
                                LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isWeek,isSeries,isMaterialProperty,isItem

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.MaterialProperty,table2.ItemID,table2.SeriesName,table2.ItemName ";

                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource 
                                LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ItemID = pc.ItemID ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,series.SeriesName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.MaterialProperty,table2.SeriesName,item.ItemName ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }
                                }

                                #endregion
                            }
                            else
                            {
                                #region isWeek,isSeries,isMaterialProperty

                                if (isPrice)
                                {
                                    con0 = @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,series.SeriesName ";
                                    con1 = @" ,table2.Weekv,table2.SeriesID,table2.MaterialProperty,table2.SeriesName ";

                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID ";
                                    con4 =
                                        @" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @"AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName ";
                                    con1 = @" ,table2.Weekv,table2.SeriesID,table2.SeriesName ";
                                    con2 = @" ,pc.MaterialProperty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @"AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID";
                                    con6 = @" ,pc.MaterialProperty ";
                                }

                                #endregion
                            }
                        }
                    }
                    else
                    {
                        if (isModel)
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isWeek,isSeries,isModel,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.SeriesID,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.ModelID,table2.ModelName,table2.ItemID,table2.SeriesName,table2.ItemName ";

                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND table3.Weekv = pc.Weekv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.SeriesID = pc.SeriesID
                           AND table3.ModelID = pc.ModelID
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
GROUP BY table3.CompanyID ,
        table3.ExtrSource ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Weekv ,
        table3.Row ,
        table3.SeriesID ,
        table3.ModelID ,
        table3.ModelName ,
        table3.ItemID ,
        table3.SeriesName ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.SeriesID,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.ModelID,table2.ModelName,table2.ItemID,table2.SeriesName,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isWeek,isSeries,isModel,isItem

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.SeriesID,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.ModelID,table2.ModelName,table2.ItemID,table2.SeriesName,table2.ItemName ";

                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName,pc.ModelID,model.ModelName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.SeriesName,table2.ModelID,table2.ModelName ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.ModelID = pc.ModelID ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isWeek,isSeries,isModel

                                if (isPrice)
                                {
                                    con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName,pc.ModelID,model.ModelName ";
                                    con1 =
                                        @" ,table2.Weekv,table2.SeriesID,table2.SeriesName,table2.ModelID,table2.ModelName ";
                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.ModelID = pc.ModelID ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName ";
                                    con1 = @" ,table2.Weekv,table2.SeriesID,table2.SeriesName ";
                                    con2 = @" ,pc.ModelID,
        model.ModelName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND table2.ExtrSource = model.ExtrSource ";
                                    con5 = @" AND table2.Weekv = pc.Weekv
                                        AND table2.SeriesID = pc.SeriesID ";
                                    con6 = @" ,pc.ModelID,model.ModelName ";
                                }

                                #endregion
                            }
                        }
                        else
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isWeek,isSeries,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.ItemID,table2.SeriesName,table2.ItemName ";

                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource 
                                        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.ItemID = pc.ItemID ";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND table3.Weekv = pc.Weekv
                           AND pc.PriceOrColor = 0
                           AND table3.SeriesID = pc.SeriesID
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.ExtrSource ,
        table3.CompanyID ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Weekv ,
        table3.Row ,
        table3.SeriesID ,
        table3.ItemID ,
        table3.SeriesName ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.ItemID,table2.SeriesName,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource 
                                        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @"AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.ItemID = pc.ItemID";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isWeek,isSeries,isItem

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.SeriesID,table2.ItemID,table2.SeriesName,table2.ItemName ";

                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource 
                                        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID
                                                AND table2.ItemID = pc.ItemID ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName ";
                                        con1 = @" ,table2.Weekv,table2.SeriesID,table2.SeriesName ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isWeek,isSeries

                                if (isPrice)
                                {
                                    con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName ";
                                    con1 = @" ,table2.Weekv,table2.SeriesID,table2.SeriesName ";
                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.SeriesID = pc.SeriesID ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con0 = @" ,pc.Weekv ";
                                    con1 = @" ,table2.Weekv ";
                                    con2 = @" ,pc.SeriesID,series.SeriesName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND table2.ExtrSource = series.ExtrSource ";
                                    con5 = @" AND table2.Weekv = pc.Weekv ";
                                    con6 = @" ,pc.SeriesID,series.SeriesName ";
                                }

                                #endregion
                            }
                        }
                    }
                }
                else
                {
                    if (isMaterialProperty)
                    {
                        if (isModel)
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isWeek,isMaterialProperty,isModel,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.MaterialProperty,table2.ModelID,table2.ModelName,table2.ItemID,table2.ItemName ";

                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND table3.Weekv = pc.Weekv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.MaterialProperty = pc.MaterialProperty
                           AND table3.ModelID = pc.ModelID
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.ExtrSource ,
        table3.CompanyID ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Weekv ,
        table3.Row ,
        table3.MaterialProperty ,
        table3.ModelID ,
        table3.ModelName ,
        table3.ItemID ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.MaterialProperty,table2.ModelID,table2.ModelName,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isWeek,isMaterialProperty,isModel,isItem

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.MaterialProperty,table2.ModelID,table2.ModelName,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID,model.ModelName ";
                                        con1 = @" ,table2.Weekv,table2.MaterialProperty,table2.ModelID,table2.ModelName";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isWeek,isMaterialProperty,isModel

                                if (isPrice)
                                {
                                    con0 = @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID,model.ModelName ";
                                    con1 = @" ,table2.Weekv,table2.MaterialProperty,table2.ModelID,table2.ModelName ";

                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con0 = @" ,pc.Weekv,pc.MaterialProperty ";
                                    con1 = @" ,table2.Weekv,table2.MaterialProperty ";
                                    con2 = @" ,pc.ModelID,model.ModelName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND table2.ExtrSource = model.ExtrSource 
       LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.Weekv = pc.Weekv ";
                                    con6 = @" ,pc.ModelID,model.ModelName ";
                                }

                                #endregion
                            }
                        }
                        else
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isWeek,isMaterialProperty,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.MaterialProperty,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.Weekv,table2.MaterialProperty,table2.ItemID,table2.ItemName ";

                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ItemID = pc.ItemID ";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND table3.Weekv = pc.Weekv
                           AND pc.PriceOrColor = 0
                           AND table3.MaterialProperty = pc.MaterialProperty
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.Yearv ,
        table3.Monthv ,
        table3.Weekv ,
        table3.Row ,
        table3.MaterialProperty ,
        table3.ItemID ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.MaterialProperty,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.Weekv,table2.MaterialProperty,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isWeek,isMaterialProperty,isItem

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.MaterialProperty,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.Weekv,table2.MaterialProperty,table2.ItemID,table2.ItemName ";

                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID 
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ItemID = pc.ItemID ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.MaterialProperty ";
                                        con1 = @" ,table2.Weekv,table2.MaterialProperty ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID 
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.MaterialProperty = pc.MaterialProperty ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isWeek,isMaterialProperty

                                if (isPrice)
                                {
                                    con0 = @" ,pc.Weekv,pc.MaterialProperty ";
                                    con1 = @" ,table2.Weekv,table2.MaterialProperty ";

                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.MaterialProperty = pc.MaterialProperty ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con0 = @" ,pc.Weekv ";
                                    con1 = @" ,table2.Weekv ";
                                    con2 = @" ,pc.MaterialProperty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @"AND table2.Weekv = pc.Weekv";
                                    con6 = @" ,pc.MaterialProperty ";
                                }

                                #endregion
                            }
                        }
                    }
                    else
                    {
                        if (isModel)
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isWeek,isModel,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.ModelID,table2.ModelName,table2.ItemID,table2.ItemName ";

                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND table3.Weekv = pc.Weekv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.ModelID = pc.ModelID
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.ExtrSource ,
        table3.CompanyID ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Weekv ,
        table3.Row ,
        table3.ModelID ,
        table3.ModelName ,
        table3.ItemID ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.ModelID,table2.ModelName,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isWeek,isModel,isItem

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                        con1 =
                                            @" ,table2.Weekv,table2.ModelID,table2.ModelName,table2.ItemID,table2.ItemName ";

                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.ModelID,model.ModelName ";
                                        con1 = @" ,table2.Weekv,table2.ModelID,table2.ModelName ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.ModelID = pc.ModelID ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isWeek,isModel

                                if (isPrice)
                                {
                                    con0 = @" ,pc.Weekv,pc.ModelID,model.ModelName ";
                                    con1 = @" ,table2.Weekv,table2.ModelID,table2.ModelName ";
                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.Weekv = pc.Weekv
                                            AND table2.ModelID = pc.ModelID ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con0 = @" ,pc.Weekv ";
                                    con1 = @" ,table2.Weekv ";
                                    con2 = @" ,pc.ModelID,model.ModelName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = @" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND table2.ExtrSource = model.ExtrSource 
       LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.Weekv = pc.Weekv ";
                                    con6 = @" ,pc.ModelID,model.ModelName ";
                                }

                                #endregion
                            }
                        }
                        else
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isWeek,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.Weekv,table2.ItemID,table2.ItemName ";

                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @"AND table2.Weekv = pc.Weekv
                                                AND table2.ItemID = pc.ItemID";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND table3.Weekv = pc.Weekv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.ExtrSource ,
        table3.CompanyID ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Weekv ,
        table3.Row ,
        table3.ItemID ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.Weekv,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isWeek,isItem

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.Weekv,table2.ItemID,table2.ItemName ";

                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.Weekv = pc.Weekv
                                                AND table2.ItemID = pc.ItemID ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv ";
                                        con1 = @" ,table2.Weekv ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.Weekv = pc.Weekv ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isWeek

                                if (isPrice)
                                {
                                    con0 = @" ,pc.Weekv ";
                                    con1 = @" ,table2.Weekv ";
                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.Weekv = pc.Weekv ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con2 = @" ,pc.Weekv,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con6 = @" ,pc.Weekv ";
                                }

                                #endregion
                            }
                        }
                    }
                }
            }
            #endregion
            #region isWeek--false

            else
            {
                if (isSeries)
                {
                    if (isMaterialProperty)
                    {
                        if (isModel)
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isSeries,isMaterialProperty,isModel,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.SeriesID,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.SeriesID,table2.MaterialProperty,table2.ModelID,table2.ModelName,table2.ItemID,table2.SeriesName,table2.ItemName ";

                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.SeriesID = pc.SeriesID
                           AND table3.MaterialProperty = pc.MaterialProperty
                           AND table3.ModelID = pc.ModelID
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.ExtrSource ,
        table3.CompanyID ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Row ,
        table3.SeriesID ,
        table3.MaterialProperty ,
        table3.ModelID , 
        table3.ModelName ,
        table3.ItemID ,
        table3.SeriesName ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 =
                                            @" ,pc.SeriesID,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.SeriesID,table2.MaterialProperty,table2.ModelID,table2.ModelName,table2.ItemID,table2.SeriesName,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isSeries,isMaterialProperty,isModel,isItem

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.SeriesID,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.SeriesID,table2.MaterialProperty,table2.ModelID,table2.ModelName,table2.ItemID,table2.SeriesName,table2.ItemName ";
                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 =
                                            @" ,pc.SeriesID,pc.MaterialProperty,series.SeriesName,pc.ModelID,model.ModelName ";
                                        con1 =
                                            @" ,table2.SeriesID,table2.MaterialProperty,table2.SeriesName,table2.ModelID,table2.ModelName ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isSeries,isMaterialProperty,isModel

                                if (isPrice)
                                {
                                    con0 =
                                        @" ,pc.SeriesID,pc.MaterialProperty,series.SeriesName,pc.ModelID,model.ModelName ";
                                    con1 =
                                        @" ,table2.SeriesID,table2.MaterialProperty,table2.SeriesName,table2.ModelID,table2.ModelName ";
                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con0 = @" ,pc.SeriesID,series.SeriesName,pc.MaterialProperty ";
                                    con1 = @" ,table2.SeriesID,table2.SeriesName,table2.MaterialProperty ";
                                    con2 = @" ,pc.ModelID,model.ModelName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND table2.ExtrSource = model.ExtrSource 
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.SeriesID = pc.SeriesID
                                        AND table2.MaterialProperty = pc.MaterialProperty ";
                                    con6 = @" ,pc.ModelID,model.ModelName ";
                                }

                                #endregion
                            }
                        }
                        else
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isSeries,isMaterialProperty,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.SeriesID,pc.MaterialProperty,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.SeriesID,table2.MaterialProperty,table2.ItemID,table2.SeriesName,table2.ItemName ";

                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
                                LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ItemID = pc.ItemID ";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.SeriesID = pc.SeriesID
                           AND table3.MaterialProperty = pc.MaterialProperty
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.ExtrSource ,
        table3.CompanyID ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Row ,
        table3.SeriesID ,
        table3.MaterialProperty ,
        table3.ItemID ,
        table3.SeriesName ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 =
                                            @" ,pc.SeriesID,pc.MaterialProperty,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.SeriesID,table2.MaterialProperty,table2.ItemID,table2.SeriesName,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource 
                                LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isSeries,isMaterialProperty,isItem

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.SeriesID,pc.MaterialProperty,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.SeriesID,table2.MaterialProperty,table2.ItemID,table2.SeriesName,table2.ItemName ";
                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource 
                                LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @"AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ItemID = pc.ItemID";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.SeriesID,pc.MaterialProperty,series.SeriesName ";
                                        con1 = @" ,table2.SeriesID,table2.MaterialProperty,table2.SeriesName ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isSeries,isMaterialProperty

                                if (isPrice)
                                {
                                    con0 = @" ,pc.SeriesID,pc.MaterialProperty,series.SeriesName ";
                                    con1 = @" ,table2.SeriesID,table2.MaterialProperty,table2.SeriesName ";
                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.SeriesID = pc.SeriesID
                                                AND table2.MaterialProperty = pc.MaterialProperty ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con0 = @" ,pc.SeriesID,series.SeriesName ";
                                    con1 = @" ,table2.SeriesID,table2.SeriesName ";
                                    con2 = @" ,pc.MaterialProperty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @"AND table2.SeriesID = pc.SeriesID";
                                    con6 = @" ,pc.MaterialProperty ";
                                }

                                #endregion
                            }
                        }
                    }
                    else
                    {
                        if (isModel)
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isSeries,isModel,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.SeriesID,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.SeriesID,table2.ModelID,table2.ModelName,table2.ItemID,table2.SeriesName,table2.ItemName ";

                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @"AND table2.SeriesID = pc.SeriesID
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.SeriesID = pc.SeriesID
                           AND table3.ModelID = pc.ModelID
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.Yearv ,
        table3.Monthv ,
        table3.Row ,
        table3.SeriesID ,
        table3.ModelID ,
        table3.ModelName ,
        table3.ItemID ,
        table3.SeriesName ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 =
                                            @" ,pc.SeriesID,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.SeriesID,table2.ModelID,table2.ModelName,table2.ItemID,table2.SeriesName,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @"AND table2.SeriesID = pc.SeriesID
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isSeries,isModel,isItem

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.SeriesID,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 =
                                            @" ,table2.SeriesID,table2.ModelID,table2.ModelName,table2.ItemID,table2.SeriesName,table2.ItemName ";
                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @"AND table2.SeriesID = pc.SeriesID
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.SeriesID,series.SeriesName,pc.ModelID,model.ModelName ";
                                        con1 = @" ,table2.SeriesID,table2.SeriesName,table2.ModelID,table2.ModelName ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.SeriesID = pc.SeriesID
                                                AND table2.ModelID = pc.ModelID ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isSeries,isModel

                                if (isPrice)
                                {
                                    con0 = @" ,pc.SeriesID,series.SeriesName,pc.ModelID,model.ModelName ";
                                    con1 = @" ,table2.SeriesID,table2.SeriesName,table2.ModelID,table2.ModelName  ";
                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.SeriesID = pc.SeriesID
                                        AND table2.ModelID = pc.ModelID ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con0 = @" ,pc.SeriesID,series.SeriesName ";
                                    con1 = @" ,table2.SeriesID,table2.SeriesName ";
                                    con2 = @" ,pc.ModelID,model.ModelName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND table2.ExtrSource = model.ExtrSource ";
                                    con5 = @" AND table2.SeriesID = pc.SeriesID ";
                                    con6 = @" ,pc.ModelID,model.ModelName ";
                                }

                                #endregion
                            }
                        }
                        else
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isSeries,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.SeriesID,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 = @" ,table2.SeriesID,table2.ItemID,table2.SeriesName,table2.ItemName ";

                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource 
                                LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @"AND table2.SeriesID = pc.SeriesID
                                                AND table2.ItemID = pc.ItemID";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.SeriesID = pc.SeriesID
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.Yearv ,
        table3.Monthv ,
        table3.Row ,
        table3.SeriesID ,
        table3.ItemID ,
        table3.SeriesName ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.SeriesID,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 = @" ,table2.SeriesID,table2.ItemID,table2.SeriesName,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource 
                                LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.SeriesID = pc.SeriesID
                                                AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isSeries,isItem

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.SeriesID,pc.ItemID,series.SeriesName,item.ItemName ";
                                        con1 = @" ,table2.SeriesID,table2.ItemID,table2.SeriesName,table2.ItemName ";
                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource 
                                LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.SeriesID = pc.SeriesID
                                                AND table2.ItemID = pc.ItemID ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.SeriesID,series.SeriesName ";
                                        con1 = @" ,table2.SeriesID,table2.SeriesName ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @"AND table2.SeriesID = pc.SeriesID";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isSeries

                                if (isPrice)
                                {
                                    con0 = @" ,pc.SeriesID,series.SeriesName ";
                                    con1 = @" ,table2.SeriesID,table2.SeriesName  ";
                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND pc.ExtrSource = series.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.SeriesID = pc.SeriesID ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con2 = @" ,pc.SeriesID,series.SeriesName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
         LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.SeriesID = series.SeriesID
                              AND table2.ExtrSource = series.ExtrSource ";
                                    con6 = @" ,pc.SeriesID,series.SeriesName ";
                                }

                                #endregion
                            }
                        }
                    }
                }
                else
                {
                    if (isMaterialProperty)
                    {
                        if (isModel)
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isMaterialProperty,isModel,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                        con1 =
                                            @" ,table2.MaterialProperty,table2.ModelID,table2.ModelName,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.MaterialProperty = pc.MaterialProperty
                           AND table3.ModelID = pc.ModelID
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.ExtrSource ,
        table3.CompanyID ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Row ,
        table3.MaterialProperty ,
        table3.ModelID ,
        table3.ModelName ,
        table3.ItemID ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 =
                                            @" ,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                        con1 =
                                            @" ,table2.MaterialProperty,table2.ModelID,table2.ModelName,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isMaterialProperty,isModel,isItem

                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                        con1 =
                                            @" ,table2.MaterialProperty,table2.ModelID,table2.ModelName,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID
                                                AND table2.ItemID = pc.ItemID ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.MaterialProperty,pc.ModelID,model.ModelName ";
                                        con1 = @" ,table2.MaterialProperty,table2.ModelID,table2.ModelName ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ModelID = pc.ModelID ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isMaterialProperty,isModel

                                if (isPrice)
                                {
                                    con0 = @" ,pc.MaterialProperty,pc.ModelID,model.ModelName ";
                                    con1 = @" ,table2.MaterialProperty,table2.ModelID,table2.ModelName ";
                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.MaterialProperty = pc.MaterialProperty
                                        AND table2.ModelID = pc.ModelID ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con0 = @" ,pc.MaterialProperty ";
                                    con1 = @" ,table2.MaterialProperty ";
                                    con2 = @" ,pc.ModelID,model.ModelName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND table2.ExtrSource = model.ExtrSource 
       LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @"AND table2.MaterialProperty = pc.MaterialProperty";
                                    con6 = @" ,pc.ModelID,model.ModelName ";
                                }

                                #endregion
                            }
                        }
                        else
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isMaterialProperty,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.MaterialProperty,pc.ItemID,item.ItemName ";
                                        con1 =
                                            @" ,table2.MaterialProperty,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ItemID = pc.ItemID ";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.MaterialProperty = pc.MaterialProperty
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.ExtrSource ,
        table3.CompanyID ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Row ,
        table3.MaterialProperty ,
        table3.ItemID ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.MaterialProperty,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.MaterialProperty,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isMaterialProperty,isItem

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.MaterialProperty,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.MaterialProperty,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @"AND table2.MaterialProperty = pc.MaterialProperty
                                                AND table2.ItemID = pc.ItemID";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.MaterialProperty ";
                                        con1 = @" ,table2.MaterialProperty ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.MaterialProperty = pc.MaterialProperty ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isMaterialProperty

                                if (isPrice)
                                {
                                    con0 = @" ,pc.MaterialProperty ";
                                    con1 = @" ,table2.MaterialProperty ";
                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.MaterialProperty = pc.MaterialProperty ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con2 = @" ,pc.MaterialProperty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con6 = @" ,pc.MaterialProperty ";
                                }

                                #endregion
                            }
                        }
                    }
                    else
                    {
                        if (isModel)
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isModel,isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.ModelID,table2.ModelName,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @"AND table2.ModelID = pc.ModelID
AND table2.ItemID = pc.ItemID";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                           AND table3.ModelID = pc.ModelID
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.ExtrSource ,
        table3.CompanyID ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Row ,
        table3.ModelID ,
        table3.ModelName ,
        table3.ItemID ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.ModelID,table2.ModelName,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.ModelID = pc.ModelID
AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isModel,isItem

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.ModelID,table2.ModelName,table2.ItemID,table2.ItemName";
                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.ModelID = pc.ModelID
AND table2.ItemID = pc.ItemID ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.ModelID,model.ModelName ";
                                        con1 = @" ,table2.ModelID,table2.ModelName ";
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.ModelID = pc.ModelID ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region isModel

                                if (isPrice)
                                {
                                    con0 = @" ,pc.ModelID,model.ModelName ";
                                    con1 = @" ,table2.ModelID,table2.ModelName ";
                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND pc.ExtrSource = model.ExtrSource ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con5 = @" AND table2.ModelID = pc.ModelID ";
                                    con6 = @" ,pc.PriceColorName ";
                                }
                                else
                                {
                                    con2 = @" ,pc.ModelID,model.ModelName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ModelID = model.ModelID
                             AND table2.ExtrSource = model.ExtrSource 
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con6 = @" ,pc.ModelID,model.ModelName ";
                                }

                                #endregion
                            }
                        }
                        else
                        {
                            if (isItem)
                            {
                                if (isDeep)
                                {
                                    #region isItem,isDeep

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con5 = @" AND table2.ItemID = pc.ItemID ";
                                        con7 = @" SELECT 
        table3.* ,
        pc.PriceColorName ,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ( ";
                                        con8 = $@" ) table3
        INNER JOIN ( SELECT *
                     FROM   ngoods.ngoods_PL_Item_SkcForPCDetail
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) pc ON table3.ExtrSource = pc.ExtrSource
                           AND table3.CompanyID = pc.CompanyID
                           AND table3.Yearv = pc.Yearv
                           AND table3.Monthv = pc.Monthv
                           AND pc.PriceOrColor = 0
                           AND table3.ItemID = pc.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table3.ExtrSource = per.ExtrSource
                           AND table3.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName
GROUP BY table3.ExtrSource ,
        table3.CompanyID ,
        table3.Yearv ,
        table3.Monthv ,
        table3.Row ,
        table3.ItemID ,
        table3.ItemName ,
        table3.DeepQty ,
        pc.PriceColorName
        {con}
ORDER BY table3.Row ,
        pc.PriceColorName  ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.ItemID,table2.ItemName ";
                                        con2 = @" ,sum(pc.DeepQty) as DeepQty,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM nods.nods_erp_SD_Mat_Item
                 WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.ItemID = pc.ItemID ";
                                    }

                                    #endregion
                                }
                                else
                                {
                                    #region isItem

                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.ItemID,item.ItemName ";
                                        con1 = @" ,table2.ItemID,table2.ItemName";
                                        con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con3 = $@" LEFT JOIN ( SELECT  *
                    FROM nods.nods_erp_SD_Mat_Item
                 WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND pc.ExtrSource = item.ExtrSource ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                        con5 = @" AND table2.ItemID = pc.ItemID ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con2 = @" ,pc.ItemID,item.ItemName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                        con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName 
         LEFT JOIN ( SELECT  *
                    FROM nods.nods_erp_SD_Mat_Item
                 WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ItemID = item.ItemID
                            AND table2.ExtrSource = item.ExtrSource ";
                                        con6 = @" ,pc.ItemID,item.ItemName ";
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region

                                if (isPrice)
                                {
                                    con2 = @" ,pc.PriceColorName,
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC ";
                                    con4 = $@" LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON table2.ExtrSource = per.ExtrSource
                           AND table2.CompanyID = per.CompanyID
                           AND pc.PriceColorName = per.PriceName ";
                                    con6 = @" ,pc.PriceColorName ";
                                }

                                #endregion
                            }
                        }
                    }
                }
            }

            #endregion
        }

        /// <summary>
        /// 返回企划结果汇总总条数
        /// </summary>
        /// <param name="Yearv"></param>
        /// <param name="Monthv"></param>
        /// <param name="ShopID"></param>
        /// <param name="isWeek"></param>
        /// <param name="isSeries"></param>
        /// <param name="isMaterialProperty"></param>
        /// <param name="isItem"></param>
        /// <param name="isDeep"></param>
        /// <param name="isPrice"></param>
        /// <returns></returns>
        /// Writer：梁家健
        /// Create Date：2017-04-24
        public int ReturnPLItemSkcForPCCount(int Yearv, int Monthv, int CountryAreaCity, string ParentAreaID, string ShopID, bool isWeek, bool isSeries, bool isMaterialProperty, bool isModel, bool isItem, bool isDeep, bool isPrice)
        {
            try
            {
                var con0 = " ";
                var con1 = " ";
                var con2 = " ";
                var con3 = " ";
                switch (CountryAreaCity)
                {
                    case 0:
                        break;
                    case 1:
                        con1 = @" INNER JOIN ( SELECT *
                     FROM   ndw.ndw_global_dictionary
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) dict ON pc.ExtrSource = dict.ExtrSource
                             AND pc.CompanyID = dict.CompanyID
                             AND pc.ParentAreaID = dict.dictValue ";
                        con2 = @" ,pc.ParentAreaID ";
                        con3 = $@" and pc.ParentAreaID='{ParentAreaID}' ";
                        break;
                    case 2:
                        con1 = @" INNER JOIN ( SELECT *
                     FROM   ndw.ndw_Shop shop
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                   ) ON pc.ExtrSource = shop.ExtrSource
                        AND pc.CompanyID = shop.CompanyID
                        AND pc.ShopID = shop.ShopID ";
                        con2 = @" ,pc.ParentAreaID ,
                                pc.ShopID ,
                                shop.ShopName";
                        con3 = $@" and pc.ShopID='{ShopID}' ";
                        break;
                    default:
                        break;
                }
                #region isWeek--True
                if (isWeek)
                {
                    if (isSeries)
                    {
                        if (isMaterialProperty)
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ModelID,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice
                                            ? @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ModelID,pc.ItemID "
                                            : @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ModelID ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice
                                        ? @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ModelID "
                                        : @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty ";
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice
                                            ? @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ItemID "
                                            : @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice
                                        ? @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty "
                                        : @" ,pc.Weekv,pc.SeriesID ";
                                }
                            }
                        }
                        else
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,pc.ModelID,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice
                                            ? @" ,pc.Weekv,pc.SeriesID,pc.ModelID,pc.ItemID "
                                            : @" ,pc.Weekv,pc.SeriesID,pc.ModelID ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice ? @" ,pc.Weekv,pc.SeriesID,pc.ModelID " : @" ,pc.Weekv,pc.SeriesID ";
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice
                                            ? @" ,pc.Weekv,pc.SeriesID,pc.ItemID "
                                            : @" ,pc.Weekv,pc.SeriesID ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice ? @" ,pc.Weekv,pc.SeriesID " : @" ,pc.Weekv ";
                                }
                            }
                        }
                    }
                    else
                    {
                        if (isMaterialProperty)
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice
                                            ? @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID,pc.ItemID "
                                            : @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice
                                        ? @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID "
                                        : @" ,pc.Weekv,pc.MaterialProperty ";
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.Weekv,pc.MaterialProperty,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice
                                            ? @" ,pc.Weekv,pc.MaterialProperty,pc.ItemID "
                                            : @" ,pc.Weekv,pc.MaterialProperty ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice
                                        ? @" ,pc.Weekv,pc.MaterialProperty "
                                        : @" ,pc.Weekv ";
                                }
                            }
                        }
                        else
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.Weekv,pc.ModelID,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice ? @" ,pc.Weekv,pc.ModelID,pc.ItemID " : @" ,pc.Weekv,pc.ModelID ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice ? @" ,pc.Weekv,pc.ModelID " : @" ,pc.Weekv ";
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.Weekv,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice ? @" ,pc.Weekv,pc.ItemID " : @" ,pc.Weekv ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice ? @" ,pc.Weekv " : @" ";
                                }
                            }
                        }
                    }
                }
                #endregion
                #region isWeek--false
                else
                {
                    if (isSeries)
                    {
                        if (isMaterialProperty)
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.SeriesID,pc.MaterialProperty,pc.ModelID,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice
                                            ? @" ,pc.SeriesID,pc.MaterialProperty,pc.ModelID,pc.ItemID "
                                            : @" ,pc.SeriesID,pc.MaterialProperty,pc.ModelID ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice
                                        ? @" ,pc.SeriesID,pc.MaterialProperty,pc.ModelID "
                                        : @" ,pc.SeriesID,pc.MaterialProperty ";
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.SeriesID,pc.MaterialProperty,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice
                                            ? @" ,pc.SeriesID,pc.MaterialProperty,pc.ItemID "
                                            : @" ,pc.SeriesID,pc.MaterialProperty ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice
                                        ? @" ,pc.SeriesID,pc.MaterialProperty "
                                        : @" ,pc.SeriesID ";
                                }
                            }
                        }
                        else
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.SeriesID,pc.ModelID,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice ? @" ,pc.SeriesID,pc.ModelID,pc.ItemID " : @" ,pc.SeriesID,pc.ModelID ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice ? @" ,pc.SeriesID,pc.ModelID " : @" ,pc.SeriesID ";
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.SeriesID,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice ? @" ,pc.SeriesID,pc.ItemID " : @" ,pc.SeriesID ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice ? @" ,pc.SeriesID " : @" ";
                                }
                            }
                        }
                    }
                    else
                    {
                        if (isMaterialProperty)
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.MaterialProperty,pc.ModelID,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice
                                            ? @" ,pc.MaterialProperty,pc.ModelID,pc.ItemID "
                                            : @" ,pc.MaterialProperty,pc.ModelID ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice
                                        ? @" ,pc.MaterialProperty,pc.ModelID "
                                        : @" ,pc.MaterialProperty ";
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.MaterialProperty,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice
                                            ? @" ,pc.MaterialProperty,pc.ItemID "
                                            : @" ,pc.MaterialProperty ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice
                                        ? @" ,pc.MaterialProperty "
                                        : @" ";
                                }
                            }
                        }
                        else
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.ModelID,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice ? @" ,pc.ModelID,pc.ItemID " : @" ,pc.ModelID ";
                                    }
                                }
                                else
                                {
                                    con0 = isPrice ? " ,pc.ModelID " : @" ";
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        con0 = @" ,pc.ItemID ";
                                    }
                                    else
                                    {
                                        con0 = isPrice ? @" ,pc.ItemID " : @" ";
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion
                var sql = $@" SELECT  COUNT(1)
FROM    ( SELECT    COUNT(1)
          FROM      ngoods.ngoods_PL_Item_SkcForPCDetail pc
                    {con1}
          WHERE     pc.ExtrSource = '{UserInfo.UserExtrSource}'
                    AND pc.CompanyID = '{UserInfo.UserCompanyId}'
                    AND pc.Yearv = {Yearv}
                    AND pc.Monthv = {Monthv}
                    AND pc.PriceOrColor = {(int)PriceOrColor.Price}
                    {con3}
          GROUP BY  pc.ExtrSource ,
                    pc.CompanyID ,
                    pc.Yearv ,
                    pc.Monthv 
                    {con2}
                    {con0}
          
        ) table1 ";
                var cmd = Helper.GetSqlStringCommand(sql);
                return Convert.ToInt32(Helper.ExecuteScalar(cmd));
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// 导出企划结果汇总
        /// </summary>
        /// <param name="Keys"></param>
        /// <returns></returns>
        public DataTable ExportPLItemSkcForPC(string Keys, int CountryAreaCity, bool isWeek, bool isSeries,
            bool isMaterialProperty, bool isModel, bool isItem, bool isDeep, bool isPrice)
        {
            try
            {
                var con0 = " ";
                var con2 = " ";
                var con3 = " ";
                var con4 = " ";
                var con5 = " ";
                var con6 = " ";
                switch (CountryAreaCity)
                {
                    case 0:
                        break;
                    case 1:
                        con4 = @",
                            pc.ParentAreaID ,
                            dictName as ParentAreaName";
                        con3 = @"inner join dw.dw_global_dictionary dict on pc.ParentAreaID=dict.dictValue";
                        con5 = @",
                            pc.ParentAreaID ,
                            dictName";
                        break;
                    case 2:
                        con4 = @",
                            pc.ParentAreaID ,
                            pc.ShopID ,
                            shop.ShopName ,
                            dictName as ParentAreaName";
                        con3 = @"inner join dw.dw_global_dictionary dict on pc.ParentAreaID=dict.dictValue
                            INNER JOIN dw.dw_Shop shop ON pc.ShopID = shop.ShopID";
                        con5 = @",
                            pc.ParentAreaID ,
                            pc.ShopID ,
                            shop.ShopName ,
                            dictName";
                        break;
                    default:
                        break;
                }

                #region isWeek--True

                if (isWeek)
                {
                    if (isSeries)
                    {
                        if (isMaterialProperty)
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 =
                                                @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";

                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 =
                                                @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 =
                                                @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";

                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 =
                                                @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,series.SeriesName,pc.ModelID,model.ModelName ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,series.SeriesName,pc.ModelID,model.ModelName ";

                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName,pc.MaterialProperty ";
                                        con2 = @" ,pc.ModelID,model.ModelName ";
                                        con6 = @" ,pc.ModelID,model.ModelName ";
                                    }
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 =
                                                @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ItemID,series.SeriesName,item.ItemName ";

                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 =
                                                @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ItemID,series.SeriesName,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 =
                                                @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,pc.ItemID,series.SeriesName,item.ItemName ";

                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,series.SeriesName ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,pc.MaterialProperty,series.SeriesName ";

                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName ";
                                        con2 = @" ,pc.MaterialProperty ";
                                        con6 = @" ,pc.MaterialProperty ";
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.Weekv,pc.SeriesID,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";

                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.Weekv,pc.SeriesID,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.Weekv,pc.SeriesID,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";

                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName,pc.ModelID,model.ModelName ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName,pc.ModelID,model.ModelName ";
                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName ";
                                        con2 = @" ,pc.ModelID,model.ModelName ";
                                        con6 = @" ,pc.ModelID,model.ModelName ";
                                    }
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.Weekv,pc.SeriesID,pc.ItemID,series.SeriesName,item.ItemName ";

                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.Weekv,pc.SeriesID,pc.ItemID,series.SeriesName,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.Weekv,pc.SeriesID,pc.ItemID,series.SeriesName,item.ItemName ";

                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.SeriesID,series.SeriesName ";
                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv ";
                                        con2 = @" ,pc.SeriesID,series.SeriesName ";
                                        con6 = @" ,pc.SeriesID,series.SeriesName ";
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (isMaterialProperty)
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 =
                                                @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";

                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 =
                                                @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 =
                                                @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";

                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID,model.ModelName ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.MaterialProperty,pc.ModelID,model.ModelName ";

                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv,pc.MaterialProperty ";
                                        con2 = @" ,pc.ModelID,model.ModelName ";
                                        con6 = @" ,pc.ModelID,model.ModelName ";
                                    }
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.Weekv,pc.MaterialProperty,pc.ItemID,item.ItemName ";

                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.Weekv,pc.MaterialProperty,pc.ItemID,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.Weekv,pc.MaterialProperty,pc.ItemID,item.ItemName ";

                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.Weekv,pc.MaterialProperty ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.MaterialProperty ";

                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv ";
                                        con2 = @" ,pc.MaterialProperty ";
                                        con6 = @" ,pc.MaterialProperty ";
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.Weekv,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";

                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.Weekv,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.Weekv,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";

                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.Weekv,pc.ModelID,model.ModelName ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv,pc.ModelID,model.ModelName ";
                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.Weekv ";
                                        con2 = @" ,pc.ModelID,model.ModelName ";
                                        con6 = @" ,pc.ModelID,model.ModelName ";
                                    }
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.Weekv,pc.ItemID,item.ItemName ";

                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.Weekv,pc.ItemID,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.Weekv,pc.ItemID,item.ItemName ";

                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.Weekv ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.Weekv ";
                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con2 = @" ,pc.Weekv ";
                                        con6 = @" ,pc.Weekv ";
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion
                #region isWeek--false

                else
                {
                    if (isSeries)
                    {
                        if (isMaterialProperty)
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 =
                                                @" ,pc.SeriesID,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";

                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 =
                                                @" ,pc.SeriesID,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 =
                                                @" ,pc.SeriesID,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 =
                                                @" ,pc.SeriesID,pc.MaterialProperty,series.SeriesName,pc.ModelID,model.ModelName ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 =
                                            @" ,pc.SeriesID,pc.MaterialProperty,series.SeriesName,pc.ModelID,model.ModelName ";
                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.SeriesID,series.SeriesName,pc.MaterialProperty ";
                                        con2 = @" ,pc.ModelID,model.ModelName ";
                                        con6 = @" ,pc.ModelID,model.ModelName ";
                                    }
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 =
                                                @" ,pc.SeriesID,pc.MaterialProperty,pc.ItemID,series.SeriesName,item.ItemName ";

                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 =
                                                @" ,pc.SeriesID,pc.MaterialProperty,pc.ItemID,series.SeriesName,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 =
                                                @" ,pc.SeriesID,pc.MaterialProperty,pc.ItemID,series.SeriesName,item.ItemName ";
                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.SeriesID,pc.MaterialProperty,series.SeriesName ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.SeriesID,pc.MaterialProperty,series.SeriesName ";
                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.SeriesID,series.SeriesName ";
                                        con2 = @" ,pc.MaterialProperty ";
                                        con6 = @" ,pc.MaterialProperty ";
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.SeriesID,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";

                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.SeriesID,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.SeriesID,pc.ModelID,model.ModelName,pc.ItemID,series.SeriesName,item.ItemName ";
                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.SeriesID,series.SeriesName,pc.ModelID,model.ModelName ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.SeriesID,series.SeriesName,pc.ModelID,model.ModelName ";
                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.SeriesID,series.SeriesName ";
                                        con2 = @" ,pc.ModelID,model.ModelName ";
                                        con6 = @" ,pc.ModelID,model.ModelName ";
                                    }
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.SeriesID,pc.ItemID,series.SeriesName,item.ItemName ";

                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.SeriesID,pc.ItemID,series.SeriesName,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.SeriesID,pc.ItemID,series.SeriesName,item.ItemName ";
                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.SeriesID,series.SeriesName ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.SeriesID,series.SeriesName ";
                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con2 = @" ,pc.SeriesID,series.SeriesName ";
                                        con6 = @" ,pc.SeriesID,series.SeriesName ";
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (isMaterialProperty)
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 =
                                                @" ,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 =
                                                @" ,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 =
                                                @" ,pc.MaterialProperty,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.MaterialProperty,pc.ModelID,model.ModelName ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.MaterialProperty,pc.ModelID,model.ModelName ";
                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.MaterialProperty ";
                                        con2 = @" ,pc.ModelID,model.ModelName ";
                                        con6 = @" ,pc.ModelID,model.ModelName ";
                                    }
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.MaterialProperty,pc.ItemID,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.MaterialProperty,pc.ItemID,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.MaterialProperty,pc.ItemID,item.ItemName ";
                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.MaterialProperty ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.MaterialProperty ";
                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con2 = @" ,pc.MaterialProperty ";
                                        con6 = @" ,pc.MaterialProperty ";
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (isModel)
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.ModelID,model.ModelName,pc.ItemID,item.ItemName ";
                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.ModelID,model.ModelName ";
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                                else
                                {
                                    if (isPrice)
                                    {
                                        con0 = @" ,pc.ModelID,model.ModelName ";
                                        con2 = @" ,pc.PriceColorName ";
                                        con6 = @" ,pc.PriceColorName ";
                                    }
                                    else
                                    {
                                        con0 = @" ,pc.ModelID,model.ModelName ";
                                    }
                                }
                            }
                            else
                            {
                                if (isItem)
                                {
                                    if (isDeep)
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.ItemID,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con0 = @" ,pc.ItemID,item.ItemName ";
                                            con2 = @" ,sum(pc.DeepQty) as DeepQty ";
                                        }
                                    }
                                    else
                                    {
                                        if (isPrice)
                                        {
                                            con0 = @" ,pc.ItemID,item.ItemName ";
                                            con2 = @" ,pc.PriceColorName ";
                                            con6 = @" ,pc.PriceColorName ";
                                        }
                                        else
                                        {
                                            con2 = @" ,pc.ItemID,item.ItemName ";
                                            con6 = @" ,pc.ItemID,item.ItemName ";
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion

                var sql = $@"SELECT  pc.Yearv ,
        pc.Monthv ,
        {con4}
        {con0} 
        {con2},
        SUM(pc.DeepQty * pc.PriceColorSKCQty * per.PriceValue) AS SumPrice ,
        SUM(pc.PriceColorSKCQty) AS SumSKC
FROM    ngoods.ngoods_PL_Item_SkcForPCDetail pc
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_PricePeriod
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) per ON pc.ExtrSource = per.ExtrSource
                           AND pc.CompanyID = per.CompanyID
                           AND per.PriceName = pc.PriceColorName
        {con3}
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Series
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) series ON pc.ExtrSource = series.ExtrSource
                              AND pc.SeriesID = series.SeriesID
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Model
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) model ON pc.ExtrSource = model.ExtrSource
                             AND pc.ModelID = model.ModelID
        LEFT JOIN ( SELECT  *
                    FROM    nods.nods_erp_SD_Mat_Item
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                  ) item ON pc.ExtrSource = item.ExtrSource
                            AND pc.ItemID = item.ItemID
WHERE   pc.ExtrSource = '{UserInfo.UserExtrSource}'
        AND pc.CompanyID = '{UserInfo.UserCompanyId}'
        AND pc.PriceOrColor = {(int)PriceOrColor.Price} 
		{Keys}
GROUP BY pc.Yearv ,
        pc.Monthv 
        {con5}
        {con0} 
        {con6}
ORDER BY pc.Yearv ,
        pc.Monthv 
        {con5}
        {con0}";
                var cmd = Helper.GetSqlStringCommand(sql);
                return Helper.ExecuteDataTable(cmd);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
    }
}
